﻿using System;
using System.Globalization;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Json
{
    static class StringExtensions
    {
        public static bool TryParse(this string target, out Int64 value, NumberFormatInfo numberFormat)
        {
            try
            {
                value = Int64.Parse(target, NumberStyles.Integer, numberFormat);
                return true;
            }
            catch (Exception)
            {
                value = Int64.MinValue;
                return false;
            }
        }

        public static bool TryParse(this string target, out Int32 value, NumberFormatInfo numberFormat)
        {
            try
            {
                value = Int32.Parse(target, numberFormat);
                return true;
            }
            catch (Exception)
            {
                value = Int32.MinValue;
                return false;
            }
        }

        public static bool TryParse(this string target, out Double value, NumberFormatInfo numberFormat)
        {
            try
            {
                value = Double.Parse(target, numberFormat);
                return true;
            }
            catch (Exception)
            {
                value = Double.MinValue;
                return false;
            }
        }
    }
}
